#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：爬虫-波波老师
@File：17-xpath城市名称.py
@Author ：文非
@Date：2021/3/1119:16
@Require： 解析所有城市的名称: https://www.aqistudy.cn/historydata/
'''
import requests
from lxml import etree

if __name__ == "__main__":
    # UA伪装
    # UA伪装
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
    }
    # 指定url
    url = "https://www.aqistudy.cn/historydata/"
    # 对指定url发送请求
    response = requests.get(url=url, headers=headers)
    page = response.text
    tree = etree.HTML(page)

    host_list_data = tree.xpath('//div[@class="bottom"]//ul/li//text()')
    print(host_list_data)
    allCity =tree.xpath('//div[@class="all"]//ul//li//a/text()')
    print(allCity)

    fp = open("./热门城市.txt","a",encoding="utf-8")
    for host in host_list_data:
        fp.write(host+" ")
    fp.write("\n")

    for all in allCity:
        fp.write(all+" ")
    # 获取响应数据
    # 持久性存储数据

